package cc.wsyw126.java.nowcoder.sword_offer;

/**
 * Created by dp on 17/3/27.
 */
public class NumberOf1 {
    public int NumberOf1(int n) {
        int i = 1;
        int k = 32;
        int count = 0;
        while (k > 0) {
            int j = i & n;
            if (j != 0) {
                count++;
            }
            i = i << 1;
            k--;
        }
        return count;
    }

    public static void main(String[] args) {
        NumberOf1 numberOf1 = new NumberOf1();
        int i = numberOf1.NumberOf1(-1);
        System.out.println("i = " + i);
    }
}
